package com.ruoyi.controller.admin.app;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.admin.AdminRichTextDB;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.admin.AdminRichTextService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/content/richText")
@Slf4j
public class RichTextController extends BaseController {

    // 增加富文本

    @Resource
    private AdminRichTextService adminRichTextService;

    /**
     * 查询富文本列表
     */
    @PreAuthorize("@ss.hasPermi('app:richText:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminRichTextDB adminRichText) {
        return adminRichTextService.selectAdminRichTextList(adminRichText);
    }

//    /**
//     * 导出富文本列表
//     */
//    @PreAuthorize("@ss.hasPermi('richText:richText:export')")
//    @Log(title = "富文本", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, AdminRichText adminRichText) {
//        List<AdminRichText> list = adminRichTextService.selectAdminRichTextList(adminRichText);
//        ExcelUtil<AdminRichText> util = new ExcelUtil<AdminRichText>(AdminRichText.class);
//        util.exportExcel(response, list, "富文本数据");
//    }

    /**
     * 获取富文本详细信息
     */
    @PreAuthorize("@ss.hasPermi('app:richText:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(adminRichTextService.selectAdminRichTextById(id));
    }

    /**
     * 新增富文本
     */
    @PreAuthorize("@ss.hasPermi('app:richText:add')")
    @Log(title = "富文本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminRichTextDB adminRichText) {
        return toAjax(adminRichTextService.insertAdminRichText(adminRichText));
    }

    /**
     * 修改富文本
     */
    @PreAuthorize("@ss.hasPermi('app:richText:edit')")
    @Log(title = "富文本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminRichTextDB adminRichText) {
        return toAjax(adminRichTextService.updateAdminRichText(adminRichText));
    }

//    /**
//     * 删除富文本
//     */
//    @PreAuthorize("@ss.hasPermi('richText:richText:remove')")
//    @Log(title = "富文本", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids) {
//        return toAjax(adminRichTextService.deleteAdminRichTextByIds(ids));
//    }

}
